package com.ipzoe.common.retrofit.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.Lists;
import lombok.Data;

import java.util.List;

/**
 * LeanCloud请求-操作会话成员
 * <p>
 * Created 2018/01/19.
 *
 * @author pfzhang
 */
@Data
public class ConversationMember {

    private Member m;

    @Data
    public static class Member{

        /** 操作 增加成员 */
        public static final String OPERATION_ADD = "AddUnique";
        /** 操作 移除成员 */
        public static final String OPERATION_REMOVE = "Remove";

        /** 操作 */
        @JsonProperty("__op")
        private String operation;

        /** client_id集合 */
        @JsonProperty("objects")
        private List<String> objects;
    }

    /**
     * 添加成员
     *
     * @param accountId 成员ID
     * @return 会话增减成员对象
     */
    public static ConversationMember addMember(String accountId) {
        return createConversationMember(accountId, Member.OPERATION_ADD);
    }

    /**
     * 移除成员
     *
     * @param accountId 成员ID
     * @return 会话增减成员对象
     */
    public static ConversationMember removeMember(String accountId) {
        return createConversationMember(accountId, Member.OPERATION_REMOVE);
    }

    /**
     * 创建会话增减成员对象
     *
     * @param accountId 成员ID
     * @param operation 操作
     * @return 会话增减成员对象
     */
    private static ConversationMember createConversationMember(String accountId, String operation) {
        ConversationMember conversationMember = new ConversationMember();
        Member member = new Member();
        member.setOperation(operation);

        List<String> objects = Lists.newArrayList();
        objects.add(accountId);
        member.setObjects(objects);

        conversationMember.setM(member);

        return conversationMember;
    }
}
